package com.hxjb.config.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Component
public class RedisPoolFactory {

	@Autowired
	RedisProperties redisProperties;
	
	@Bean
	public JedisPool JedisPoolFactory() {
		JedisPoolConfig poolConfig = new JedisPoolConfig();
		poolConfig.setMaxIdle(redisProperties.getPoolMaxIdle());
		poolConfig.setMaxTotal(redisProperties.getPoolMaxTotal());
		poolConfig.setMaxWaitMillis(redisProperties.getPoolMaxWait() * 1000);
		JedisPool jp = new JedisPool(poolConfig, redisProperties.getHost(), redisProperties.getPort(),
				redisProperties.getTimeout()*1000, redisProperties.getPassword(), redisProperties.getDatabase());
		return jp;
	}
	
}